package design.prototype;

import java.util.Date;

//克隆羊类，有两个属性，DNA和其克隆时间
public class ClonedSheep implements Cloneable{

    private String DNA;

    private Date birthday;

    public ClonedSheep(String DNA, Date birthday) {
        this.DNA = DNA;
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "ClonedSheep{" +
                "DNA='" + DNA + '\'' +
                ", birthday=" + birthday +
                '}';
    }

    public String getDNA() {
        return DNA;
    }

    public void setDNA(String DNA) {
        this.DNA = DNA;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public ClonedSheep() {
    }

    //重写克隆方法
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Object obj = super.clone();

        //实现深克隆,将属性变量也进行克隆
        ClonedSheep clone = (ClonedSheep) obj;
        clone.birthday = (Date) this.birthday.clone();

        return clone;
    }
}
